function breakout_of_frame()
{
	if (top.location != location) {
		top.location.href = "Default.aspx" ;
	}
}

function repl(s,y,t) 
{ 
    var i; 
    var s2=s; 
    var y2=y;
    var t2=t;
    
    while(s2.indexOf(y2)>=0) 
    { 
    i = s2.indexOf(y2); 
    s2 = s2.substring(0, i) + t2 + s2.substring(i + y2.length, s2.length); 
    } 
    return s2; 
} 

		
function setTopMenu(titleImg,titleDesc,tileName,parentid, t, count)
{
	for(var i=0; i<count; i++)
	{
		$('T'+i).className = "";
	}
	$(t).className	= "ms-navline";
	var menuIMG		= document.getElementById("MenuIMG");
	var menuDesc	= document.getElementById("MenuDesc");
	var menuTitle	= document.getElementById("MenuTitle");
	menuIMG.src		= titleImg;
	menuDesc.innerText	= titleDesc;
	menuTitle.innerText	= tileName;
	
	if(parentid == 1)
	{
		parent.location = 'Default.aspx';
//		parent.Left.location	= 'QuickLanuch.aspx';
//		parent.Main.location	= 'Main.aspx';
	}
	else 
	{
		parent.Left.location	= 'Left.aspx?ParentID='+parentid;
		parent.Main.location	= 'Blank.aspx';
//		parent.Main.location	= href;
	}
}

function setSubMenu(tdID,url,tdCount)
{
	for(var tempInt=0;tempInt<tdCount;tempInt++)
	{
		var td		= document.getElementById('td'+tempInt);
		if(td != null) td.className	= 'ms-unselectednav';
	}
	var td		= document.getElementById(tdID);
	td.className	= 'ms-selectednav';
	td.focus();
	parent.Main.location	= url;
}

function setMyFavourites(tdID,url,tdCount)
{
	for(var tempInt=0;tempInt<tdCount;tempInt++)
	{
		var td		= document.getElementById('td'+tempInt);
		td.className	= 'ms-navheader';
	}
	var td		= document.getElementById(tdID);
	td.className	= 'ms-selectednav';
	td.focus();
	parent.Main.location	= url;
}

function Browseris () {
	var agt = navigator.userAgent.toLowerCase();
        this.osver = 1.0;
        if (agt)
        {
            var stOSVer = agt.substring(agt.indexOf("windows ") + 11);
	    this.osver = parseFloat(stOSVer);
        }
	this.major = parseInt(navigator.appVersion);
	this.nav = ((agt.indexOf('mozilla')!=-1)&&((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible')==-1)));
 	this.nav2 = (this.nav && (this.major == 2));
	this.nav3 = (this.nav && (this.major == 3));
	this.nav4 = (this.nav && (this.major == 4));
	this.nav6 = this.nav && (this.major == 5);
	this.nav6up = this.nav && (this.major >= 5);
	this.nav7up = false;
	if (this.nav6up)
	{
		var navIdx = agt.indexOf("netscape/");
		if (navIdx >=0 )
			this.nav7up = parseInt(agt.substring(navIdx+9)) >= 7;
	}
	this.ie = (agt.indexOf("msie")!=-1);
	this.aol = this.ie && agt.indexOf(" aol ")!=-1;
	if (this.ie)
		{
		var stIEVer = agt.substring(agt.indexOf("msie ") + 5);
		this.iever = parseInt(stIEVer);
		this.verIEFull = parseFloat(stIEVer);
		}
	else
		this.iever = 0;
	this.ie3 = ( this.ie && (this.major == 2));
	this.ie4 = ( this.ie && (this.major == 4));
	this.ie4up = this.ie && (this.major >=4);
	this.ie5up = this.ie && (this.iever >= 5);
	this.ie55up = this.ie && (this.verIEFull >= 5.5);
	this.ie6up = this.ie && (this.iever >= 6);
    this.win16 = ((agt.indexOf("win16")!=-1)
               || (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1)
               || (agt.indexOf("windows 16-bit")!=-1) );
    this.win31 = (agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                 (agt.indexOf("windows 16-bit")!=-1);
    this.win98 = ((agt.indexOf("win98")!=-1)||(agt.indexOf("windows 98")!=-1));
    this.win95 = ((agt.indexOf("win95")!=-1)||(agt.indexOf("windows 95")!=-1));
    this.winnt = ((agt.indexOf("winnt")!=-1)||(agt.indexOf("windows nt")!=-1));
    this.win32 = this.win95 || this.winnt || this.win98 || 
                 ((this.major >= 4) && (navigator.platform == "Win32")) ||
                 (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1);
    this.os2   = (agt.indexOf("os/2")!=-1) 
                 || (navigator.appVersion.indexOf("OS/2")!=-1)  
                 || (agt.indexOf("ibm-webexplorer")!=-1);
    this.mac    = (agt.indexOf("mac")!=-1);
    this.mac68k = this.mac && ((agt.indexOf("68k")!=-1) || 
                               (agt.indexOf("68000")!=-1));
    this.macppc = this.mac && ((agt.indexOf("ppc")!=-1) || 
                               (agt.indexOf("powerpc")!=-1));
    this.w3c = this.nav6up;
}
var browseris = new Browseris();

var displayBar=true;
function switchBar(obj)
{
	if (displayBar)
	{
		parent.frame.cols="0,*";
		displayBar=false;
		obj.title="Show Side bar";
	}else{
		parent.frame.cols="150,*";
		displayBar=true;
		obj.title="Hide side bar";
	}
}

function ReloadFrame()
{
	parent.Top.location.reload();
	parent.Left.location.reload();
	parent.Main.location.href = parent.Main.location.href;
}
		
function OnItem_Active(elm)
{
    elm.bgColor='#eaeaea';
    return true;
}

function OnItem_InActive(elm)
{
	elm.bgColor='';
    return true;
}

function RowItem_Active(elm,css)
{
    elm.className=css;
    return true;
}

function RowItem_InActive(elm,css)
{
	elm.className=css;
    return true;
}

function ShowAllTimesheetDetail(tableID)
{
	var detailID= "detailRow";
	var showRow	= document.getElementById(detailID);
	var?myTable =?document.getElementById(tableID);
	if(myTable != null)
	{	
		if(showRow != null) myTable.deleteRow(showRow.rowIndex);
		var num		= myTable.rows.length;
		var ids		= '0';
		for (i=1;i<num-1;i++)
		{
			ids = ids+","+myTable.rows(i).cells(0).innerText;
		}
		var randomid = ''+Math.floor(Math.random() * (1000000 + 1));
		var myAjax = new Ajax.Request(
						"../Timesheet/AjaxTimesheetDetail.aspx",
						{method: 'get', parameters: 'id='+ids+'&random='+randomid, onComplete: addTimesheetTR}
						);
		var hidden		= document.getElementById("ucTimesheetList_showdetail");
		if(hidden != null) hidden.value = 1;
	}
}

function addTimesheetTR(originalRequest)
{
    var Dom = new ActiveXObject("Microsoft.XMLDOM") 
    Dom.async=true  
    Dom.loadXML(originalRequest.responseText) 
    if(Dom.parseError.errorCode != 0)  
    { 
        delete(Dom)
        return(false) 
    } 
    else 
    {
        var nodeList = Dom.documentElement.selectNodes("//VIEW_TK_TS_List");
        for(var i=0;i<nodeList.length;i++)
        {
			var task = " ";
			var taskLog = " ";
			var summary = " ";
			if(nodeList[i].selectSingleNode("Task") != null)
				task = ""+nodeList[i].selectSingleNode("Task").text;
			if(nodeList[i].selectSingleNode("TaskLog") != null)
				taskLog = ""+nodeList[i].selectSingleNode("TaskLog").text;
			if(nodeList[i].selectSingleNode("Summary") != null)
				summary = ""+nodeList[i].selectSingleNode("Summary").text;
			var timesheetid = nodeList[i].selectSingleNode("TimesheetID").text;
			var?newRow	= $(timesheetid).parentElement.insertRow($(timesheetid).rowIndex+1);
			newRow.id	= "detailrow"+i;
			newRow.className = "datagrid_row";
			newRow.style.backgroundColor = $(timesheetid).style.backgroundColor;
			var?newTd?=?newRow.insertCell(0);
			newTd.className	= "datagrid_item";
			newTd.innerText	= " ";
			newTd?=?newRow.insertCell(1);
			newTd.className= "datagrid_item_task";
			newTd.colSpan	= 2;
			newTd.innerText= task;
			newTd?=?newRow.insertCell(2);
			newTd.className= "datagrid_item_task";
			newTd.colSpan	= 5;
			newTd.innerText= taskLog;
			var?noteTd?=?newRow.insertCell(3);
			noteTd.className= "datagrid_item_task";
			noteTd.colSpan	= 4;
			noteTd.innerText= summary;
		}
        delete(Dom)
    }
}


function HideAllTimesheetDetail(tableID)
{
	var detailID= "detailRow";
	var?myTable =?document.getElementById(tableID);
	var num		= myTable.rows.length;
	for (i=0;i<num;i++)
	{
		var showRow	= document.getElementById(detailID+i);
		if(showRow != null) myTable.deleteRow(showRow.rowIndex);
	}
	var hidden		= document.getElementById("ucTimesheetList_showdetail");
	hidden.value = 0;
}

function showorhideTimesheet(tableID, hidden)
{
	var hidden		= document.getElementById(hidden);
	if(hidden.value == 1) 
	{
		ShowAllTimesheetDetail(tableID);
		document.getElementById('show').style.display='none';
		document.getElementById('hide').style.display='';
	}
}

function showorhideTask(tableID, hidden)
{
	var hidden		= document.getElementById(hidden);
	if(hidden.value == 1) 
	{
		ShowAllTaskDetail(tableID);
		document.getElementById('show').style.display='none';
		document.getElementById('hide').style.display='';
	}
}

function ShowAllTaskDetail(tableID)
{
	var detailID= "detailRow";
	var showRow	= document.getElementById(detailID);
	var?myTable =?document.getElementById(tableID);
	if(myTable != null)
	{	
		if(showRow != null) myTable.deleteRow(showRow.rowIndex);
		var num		= myTable.rows.length;
		var ids		= '0';
		for (i=1;i<num-1;i++)
		{
			ids = ids+","+myTable.rows(i).cells(1).innerText;
		}
		var randomid = ''+Math.floor(Math.random() * (1000000 + 1));
		var myAjax = new Ajax.Request(
						"../Task/AjaxTaskDetail.aspx",
						{method: 'get', parameters: 'id='+ids+'&random='+randomid, onComplete: addTaskTR}
						);
		var hidden		= document.getElementById("ucTaskList_showdetail");
		if(hidden != null) hidden.value = 1;
	}
}

function HideAllTaskDetail(tableID)
{
	var detailID= "detailRow";
	var?myTable =?document.getElementById(tableID);
	var num		= myTable.rows.length;
	for (i=0;i<num;i++)
	{
		var showRow	= document.getElementById(detailID+i);
		if(showRow != null) myTable.deleteRow(showRow.rowIndex);
	}
	var hidden		= document.getElementById("ucTaskList_showdetail");
	hidden.value = 0;
}

function addTaskTR(originalRequest)
{
    var Dom = new ActiveXObject("Microsoft.XMLDOM") 
    Dom.async=true  
    Dom.loadXML(originalRequest.responseText) 
    if(Dom.parseError.errorCode != 0)  
    { 
        delete(Dom)
        return(false) 
    } 
    else 
    {
        var nodeList = Dom.documentElement.selectNodes("//TK_Task");
        for(var i=0;i<nodeList.length;i++)
        {
			var desc = " ";
			if(nodeList[i].selectSingleNode("Description") != null)
				desc = ""+nodeList[i].selectSingleNode("Description").text;
			var taskid = nodeList[i].selectSingleNode("TaskID").text;
			var?newRow	= $(taskid).parentElement.insertRow($(taskid).rowIndex+1);
			newRow.id	= "detailrow"+i;
			newRow.className = "datagrid_row";
			newRow.style.backgroundColor = $(taskid).style.backgroundColor;
			var?newTd?=?newRow.insertCell(0);
			newTd.className	= "datagrid_item";
			newTd.colSpan	= 5;
			newTd.innerText	= " ";
			var?taskTd?=?newRow.insertCell(1);
			taskTd.className= "datagrid_item_task";
			taskTd.colSpan	= 4;
			taskTd.innerText= desc;
		}
        delete(Dom)
    }
}

function ShowModel(url,width,height)
{
? ?	var top		=((window.screen.availHeight-height)/2); 
?	var left	=((window.screen.availWidth-width)/2); ?
	var params	= "top="+top+",left="+left+",toolbar=no,menubar=no,scrollbars=no,?resizable=no,location=no,?status=no,width="+width+",height="+height+"px";
	window.open(url,'newwindow',params);
}

function ShowDialog(url, width, height)
{
? ?	var top		=((window.screen.availHeight-height)/2); 
?	var left	=((window.screen.availWidth-width)/2); ?
	var params	= "top:"+top+";left:"+left+";toolbar:no;menubar:no;scrollbars:no;resizable:no;location:no;status:no;dialogWidth:"+width+"px;dialogHeight:"+height+"px;";
	showModalDialog(url,'newwindow',params);
}

function loadBar(fl)
//fl is show/hide flag
{
  var x,y;
  if (self.innerHeight)
  {// all except Explorer
    x = self.innerWidth;
    y = self.innerHeight;
  }
  else 
  if (document.documentElement && document.documentElement.clientHeight)
  {// Explorer 6 Strict Mode
   x = document.documentElement.clientWidth;
   y = document.documentElement.clientHeight;
  }
  else
  if (document.body)
  {// other Explorers
   x = document.body.clientWidth;
   y = document.body.clientHeight;
  }
	
    var el=document.getElementById('loader');
	if(null!=el)
	{
		var top = (y/2) - 50;
		var left = (x/2) - 150;
		if( left<=0 ) left = 10;
		el.style.visibility = (fl==1)?'visible':'hidden';
		el.style.display = (fl==1)?'block':'none';
		el.style.left = left + "px"
		el.style.top = top + "px";
		el.style.zIndex = 2;
	}
}

function refresh()
{
	window.location = window.location;
}

function refreshopener()
{
	if (window.opener != null)
		window.opener.location = window.opener.location;
}

function Print() 
{ 
		if (confirm('Print it?')) { 
		window.print();
		} 
}

function addAttachment(){
	var randomid = 'file'+Math.floor(Math.random() * (1000000 + 1));
	var t=document.createElement('input');
	t.setAttribute('id',randomid);
	t.setAttribute('type','file');
	t.style.display='none';
	t.onchange=function(){
		document.getElementById('fileloc').innerHTML += t.value+"<BR>";
	};
	$('fileloc').appendChild(t);
	t.click();
}

function addFile1() 
{
	var randomid = 'file'+Math.floor(Math.random() * (1000000 + 1));
	var str = '<INPUT type="file" size="50" NAME="'+randomid+'" id="'+randomid+'">';
	document.getElementById('fileloc').insertAdjacentHTML("beforeEnd",str) 
	$(randomid).style.display='none';
	$(randomid).onchange=function(){
		$('fileloc').innerHTML += $(randomid).value+"<BR>";
	};
	$(randomid).click();
} 

function addFile() 
{ 
	var fileName = "attach";
	var fileBlock = $('fileBlock'); 
	var oDiv = document.createElement("div"); 
	oDiv.innerHTML = "<input type=\"file\" name=\"" + fileName + "\" class=\"listbox\"  style=\"WIDTH: 80%\" />&nbsp;&nbsp;<a href='#' onclick=\"delFile(this)\">remove</a>"; 
	fileBlock.appendChild(oDiv);
} 

function delFile(obj) 
{ 
	var oDiv = obj.parentNode; 
	var fileBlock = document.getElementById("fileBlock"); 
	fileBlock.removeChild(oDiv); 
} 

function ShowImage(value,img)
{
	if(value.length>5&&value.indexOf(':')==1&&(value.length-value.lastIndexOf('.'))==4&&CheckExt(value))
    {
		var img1=document.createElement('img');
		img1.setAttribute('src','file://localhost/'+value);
		img1.setAttribute('width','120');
		img1.setAttribute('height','90');
		$('imgdes').style.visibility="hidden";
		img.appendChild(img1);
    }
}

function CheckExt(ext)
{
    var patn = /\.jpg$|\.jpeg$|\.png$|\.bmp$|\.gif$/i;
	if(patn.test(ext))
	{
		return true;
	}
	else
	{
		alert("ONLY jpg,jpeg,png,bmp and gif files allowed.");
		return false;
	}
}

function SetCurrentStartTime(startInputBox)
{
	var My_date=new Date();
	var H=My_date.getHours();
	var M=My_date.getMinutes();
	var S=My_date.getSeconds();
	$(startInputBox+'_txtHour').value = H;
	$(startInputBox+'_txtMinute').value = M;
}

function SetCurrentFinishTime(startInputBox, finishInputBox)
{
	var My_date=new Date();
	var H=parseInt(My_date.getHours());
	var M=parseInt(My_date.getMinutes());
	var S=parseInt(My_date.getSeconds());
	var startH = parseInt($(startInputBox+'_txtHour').value);
	var startM = parseInt($(startInputBox+'_txtMinute').value);
	if((H*60+M) > (startH*60+startM))
	{
		$(finishInputBox+'_txtHour').value = H;
		$(finishInputBox+'_txtMinute').value = M;
	}
	else if(((H+24)*100+M) < 3300)
	{
		$(finishInputBox+'_txtHour').value = H+24;
		$(finishInputBox+'_txtMinute').value = M;
	}
}

function InitTheme()
{
	document.previewImage.src=$('ucChangeTheme_listThemes').options[$('ucChangeTheme_listThemes').selectedIndex].value;
}
function SetPreview()
{
	document.previewImage.src=$('ucChangeTheme_listThemes').options[$('ucChangeTheme_listThemes').selectedIndex].value;
}


//---------------------------------------------------------
/*
These cookie functions are downloaded from 
http://www.mach5.com/support/analyzer/manual/html/General/CookiesJavaScript.htm
*/	
function _getCookie(name) 
{ 
	var start = document.cookie.indexOf(name+"="); 
	var len = start+name.length+1; 
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
	if (start == -1) return null; 
	var end = document.cookie.indexOf(";",len); 
	if (end == -1) end = document.cookie.length; 
	return unescape(document.cookie.substring(len,end)); 
} 

// get the lognon user from cognos 8 cookie
function getLogonUser()	
{
	var username = null;
	var cookieValue = _getCookie("cc_session");	
	if(cookieValue && cookieValue!='')
	{
		var start = cookieValue.indexOf("e_user:")
		if((!start))
			return null;
		
		var e_user = cookieValue.substring(start,cookieValue.length);
		var end = e_user.indexOf("|");
		if((!end))
			return null;
			
		username = unescape(e_user.substring(7,end));
	}
	return username;
}

/*
//---------------------------------------------------------
// export result to excel
//---------------------------------------------------------

// export html content to excel
function printToExcel(html) {
    try {
        var ExApp = new ActiveXObject("Excel.Application")
        var ExWBk = ExApp.workbooks.add()
        var ExWSh = ExWBk.worksheets(1)
        ExApp.DisplayAlerts = false
        ExApp.visible = true
    } catch (err) {
        alert(err.description)
        return false
    }
    window.clipboardData.setData("Text", html);
    ExWBk.worksheets(1).Paste;
    ExWBk.worksheets(1).Columns.AutoFit;
    ExWBk.worksheets(1).Rows.AutoFit;
}

// export table content to excel 
function exportToExcel(table) {
    if (confirm("Are you sure to import?")) {
        //   Start   Excel   and   get   Application   object. 
        var oXL = new ActiveXObject("Excel.Application");
        //   Get   a   new   workbook. 
        var oWB = oXL.Workbooks.Add();
        var oSheet = oWB.ActiveSheet;
        var hang = table.rows.length;
        var lie = table.rows(0).cells.length;
        //   Add   table   headers   going   cell   by   cell. 
        for (i = 0; i < hang; i++) {
            for (j = 0; j < lie; j++) {
                oSheet.Cells(i + 1, j + 1).Value = table.rows(i).cells(j).innerText;
            }
        }
        oXL.Visible = true;
        oXL.UserControl = true;
    }
}
*/